import { defineStore } from "pinia";
export const useTagStore = defineStore("tags", {
  state: () => ({
    tags: [],
  }),
  getters: {
    getTags: (state) => state.tags,
  },
  actions: {
    setTag(tags: any) {
      this.tags = tags;
    },
    addTag(tag: any) {
      const item = this.tags.find((item: any) => item.path === tag.path);
      if (!item) this.tags.push(tag as never);
    },
    removeTag(index: number) {
      this.tags.splice(index, 1);
    },
    removeOtherTag(path: any) {
      const item = this.tags.find((item: any) => item.path === path);
      this.tags = [item as never];
    },
    clearAllTag() {
      this.tags = [];
    },
  },
});
